package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.Hostel;
import com.zyg.pojo.Major;
import com.zyg.pojo.Student;
import com.zyg.pojo.Clazz;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface StudentMapper extends BaseMapper<Student> {
    @Override
    @Select("select student_id,student_name,student_sex,clazz_id,hostel_id,major_id from student ${ew.customSqlSegment}")
    @Results({
            @Result(property = "studentId", column = "student_id"),
            @Result(property = "studentName", column = "student_name"),
            @Result(property = "studentSex", column = "student_sex"),
            @Result(property = "clazz", column = "clazz_id", javaType = Clazz.class,
                    one = @One(select = "com.zyg.dao.ClazzMapper.selectById")),
            @Result(property = "hostel", column = "hostel_id", javaType = Hostel.class,
                    one = @One(select = "com.zyg.dao.HostelMapper.selectById")),
            @Result(property = "major", column = "major_id", javaType = Major.class,
                    one = @One(select = "com.zyg.dao.MajorMapper.selectById"))
    })
    List<Student> selectList(IPage<Student> page, @Param(Constants.WRAPPER) Wrapper<Student> queryWrapper);
}
